package vip.xiaonuo.smzq.modular.kcl.controller;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vip.xiaonuo.auth.core.pojo.SaBaseLoginUser;
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
import vip.xiaonuo.smzq.modular.kcl.entity.Zsksc;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.ZskResult;
import vip.xiaonuo.smzq.modular.kcl.service.IZskscService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 知识库收藏
 *
 * @author sqq
 * @since 2024-10-16
 */
@Api(tags = "知识库收藏")
@RestController
@RequestMapping("/kcl/zsksc")
@Validated
public class ZskscController {

    @Resource
    private IZskscService iZskscService;

    /**
     * 添加知识库收藏
     */
    @ApiOperation("添加知识库收藏")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid Zsksc zsksc) {
        SaBaseLoginUser saBaseLoginUser = StpLoginUserUtil.getLoginUser();
        zsksc.setUserid(saBaseLoginUser.getId());
        iZskscService.addzsksc(zsksc);
        return CommonResult.ok();
    }

    /**
     * 删除知识库收藏
     */
    @ApiOperation("删除知识库收藏")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @Valid Zsksc zsksc) {
        SaBaseLoginUser saBaseLoginUser = StpLoginUserUtil.getLoginUser();
        LambdaQueryWrapper<Zsksc> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Zsksc::getUserid,saBaseLoginUser.getId());
        queryWrapper.eq(Zsksc::getZskid,zsksc.getPkid());
        iZskscService.remove(queryWrapper);
        return CommonResult.ok();
    }

    /**
     * 编辑知识库收藏
     */
    @ApiOperation("编辑知识库收藏")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid Zsksc zsksc) {
        iZskscService.updateById(zsksc);
        return CommonResult.ok();
    }

    /**
     * 知识库收藏分页查询
     */
    @ApiOperation("知识库收藏分页查询")
    @GetMapping("/zskscPage")
    public CommonResult<Page<ZskResult>> zskscPage(
            @ApiParam(name = "current", value = "页数", example = "1", required = true) @RequestParam long current,
            @ApiParam(name = "size", value = "每页数量", example = "20", required = true) @RequestParam long size
    ) {
        return CommonResult.data(iZskscService.zskscPage(current,size));
    }
}
